class Solution(object):
    def uniquePathsWithObstacles(self, obstacleGrid):
        """
        :type obstacleGrid: List[List[int]]
        :rtype: int
        """
        nRow = len(obstacleGrid)
        nCol = len(obstacleGrid[0])
        dp = [[0 for _ in range(nCol)] for _ in range(nRow)]
        dp[0][0] = 1 if obstacleGrid[0][0]==0 else 0
        for r in range(nRow):
            for c in range(nCol):
                if obstacleGrid[r][c]==1:
                    continue
                if r-1>=0 and obstacleGrid[r-1][c]==0:
                    dp[r][c] += dp[r-1][c]
                if c-1>=0 and obstacleGrid[r][c-1]==0:
                    dp[r][c] += dp[r][c-1]
        return dp[nRow-1][nCol-1]
